package interfaces.menu.joinGame.gamesTable;

import java.io.Serializable;
import java.util.List;

import logic.common.game.GameMode;
import main.GameCycle;

public class GamesTableWidget implements Serializable {
	
	private static final long serialVersionUID = 3L;
	
	private GameCycle gameCycle;
	private int ping;
	private List<PlayerWidget> players;
	
	private int hashCode;
	
	public GamesTableWidget() {}
	
	public GamesTableWidget(GameCycle gameCycle, List<PlayerWidget> players) {
		this.gameCycle = gameCycle;
		this.players = players;
		
		int ipCode = getIp().hashCode();
		int mapCode = getCurrentMap().hashCode();
		int serverNameCode = getServerName().hashCode();
		hashCode = ipCode + getPing() + mapCode + serverNameCode;
	}
	
	public void setPing(int ping) { this.ping = ping; }
	
	public String getServerName() { return gameCycle.getGameName(); }
	
	public String getIp() { return gameCycle.getIP(); }
	
	public GameCycle getGameCycle() { return gameCycle; }
	
	public GameMode getGameMode() { return gameCycle.getGameMode(); }
	
	public String getCurrentMap() { return gameCycle.getCurrentMap(); }
	
	public int getMaxPlayers() { return gameCycle.getMaxPlayers(); }
	
	public String getTablePlayers() { return players.size() + "/" + getMaxPlayers(); }
	
	public int getPing() { return ping; }
	
	public List<PlayerWidget> getPlayers() { return players; }
	
	public boolean hasFriendlyFire() { return gameCycle.hasFriendlyFire(); }
	
	@Override
	public int hashCode() { return hashCode; }
}